package com.samphanie.auiu.admin.domain.vo;

import com.samphanie.auiu.mbg.model.SysMenu;
import lombok.Builder;
import lombok.Data;
import lombok.With;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Data
@With
@Builder
public class MenuVo implements Serializable {
    private static final long serialVersionUID = 8834796639166056731L;

    private Long id;
    private Long parentId;
    private String name;
    private String title;
    private String component;
    private String icon;
    private String path;
    private String redirect;
    private Integer sort;
    private boolean hideInBread;
    private boolean hideInMenu;
    private boolean hideChildren;
    private boolean notCache;
    private Integer type;
    private String link;
    private String remark;
    @Builder.Default
    private boolean expand = true;

    private List<MenuVo> children;
    @Builder.Default
    private List<ResourceVo> operations = new ArrayList<>();

    public static Function<SysMenu, MenuVo> fromMenuVo = (menu) -> MenuVo.builder()
            .id(menu.getId())
            .parentId(menu.getParentId())
            .title(menu.getTitle())
            .name(menu.getName())
            .component(menu.getComponent())
            .path(menu.getPath())
            .hideInMenu(menu.isHidden())
            .hideInBread(menu.isHideHeader())
            .hideChildren(menu.isHideChildren())
            .notCache(menu.isKeepAlive())
            .icon(menu.getIcon())
            .redirect(menu.getRedirect())
            .sort(menu.getSort())
            .type(menu.getType())
            .link(menu.getTarget())
            .build();

}
